package o;

import androidx.annotation.Nullable;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import java.util.ArrayDeque;

public abstract class add<I extends DecoderInputBuffer, O extends acx, E extends Exception> implements acy<I, O, E> {
    private final O[] ʻ;
    private E ʼ;
    private int ʽ;
    private final ArrayDeque<I> ˊ = new ArrayDeque();
    private int ˊॱ;
    private final I[] ˋ;
    private final Object ˎ = new Object();
    private final ArrayDeque<O> ˏ = new ArrayDeque();
    private boolean ͺ;
    private final Thread ॱ;
    private boolean ॱˊ;
    private I ॱॱ;
    private int ᐝ;

    protected abstract O ʻ();

    @Nullable
    protected abstract E ˋ(I i, O o, boolean z);

    protected abstract E ॱ(Throwable th);

    protected abstract I ॱॱ();

    public /* synthetic */ Object ˏ() throws Exception {
        return ᐝ();
    }

    public /* synthetic */ void ˏ(Object obj) throws Exception {
        ˎ((DecoderInputBuffer) obj);
    }

    public /* synthetic */ Object ॱ() throws Exception {
        return ˊ();
    }

    protected add(I[] iArr, O[] oArr) {
        int i = 0;
        this.ˋ = iArr;
        this.ᐝ = iArr.length;
        for (int i2 = 0; i2 < this.ᐝ; i2++) {
            this.ˋ[i2] = ॱॱ();
        }
        this.ʻ = oArr;
        this.ʽ = oArr.length;
        while (i < this.ʽ) {
            this.ʻ[i] = ʻ();
            i++;
        }
        this.ॱ = new Thread(this) {
            final /* synthetic */ add ˋ;

            {
                this.ˋ = r1;
            }

            public void run() {
                this.ˋ.ͺ();
            }
        };
        this.ॱ.start();
    }

    protected final void ˋ(int i) {
        boolean z;
        int i2 = 0;
        if (this.ᐝ == this.ˋ.length) {
            z = true;
        } else {
            z = false;
        }
        amm.ˏ(z);
        DecoderInputBuffer[] decoderInputBufferArr = this.ˋ;
        int length = decoderInputBufferArr.length;
        while (i2 < length) {
            decoderInputBufferArr[i2].ˊ(i);
            i2++;
        }
    }

    public final I ˊ() throws Exception {
        I i;
        synchronized (this.ˎ) {
            DecoderInputBuffer decoderInputBuffer;
            ʽ();
            amm.ˏ(this.ॱॱ == null);
            if (this.ᐝ == 0) {
                decoderInputBuffer = null;
            } else {
                DecoderInputBuffer[] decoderInputBufferArr = this.ˋ;
                int i2 = this.ᐝ - 1;
                this.ᐝ = i2;
                decoderInputBuffer = decoderInputBufferArr[i2];
            }
            this.ॱॱ = decoderInputBuffer;
            i = this.ॱॱ;
        }
        return i;
    }

    public final void ˎ(I i) throws Exception {
        synchronized (this.ˎ) {
            ʽ();
            amm.ˊ(i == this.ॱॱ);
            this.ˊ.addLast(i);
            ʼ();
            this.ॱॱ = null;
        }
    }

    public final O ᐝ() throws Exception {
        O o;
        synchronized (this.ˎ) {
            ʽ();
            if (this.ˏ.isEmpty()) {
                o = null;
            } else {
                acx o_acx = (acx) this.ˏ.removeFirst();
            }
        }
        return o;
    }

    protected void ˋ(O o) {
        synchronized (this.ˎ) {
            ˎ((acx) o);
            ʼ();
        }
    }

    public final void ˋ() {
        synchronized (this.ˎ) {
            this.ॱˊ = true;
            this.ˊॱ = 0;
            if (this.ॱॱ != null) {
                ˋ(this.ॱॱ);
                this.ॱॱ = null;
            }
            while (!this.ˊ.isEmpty()) {
                ˋ((DecoderInputBuffer) this.ˊ.removeFirst());
            }
            while (!this.ˏ.isEmpty()) {
                ((acx) this.ˏ.removeFirst()).ˋ();
            }
        }
    }

    public void ˎ() {
        synchronized (this.ˎ) {
            this.ͺ = true;
            this.ˎ.notify();
        }
        try {
            this.ॱ.join();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }

    private void ʽ() throws Exception {
        if (this.ʼ != null) {
            throw this.ʼ;
        }
    }

    private void ʼ() {
        if (ˏॱ()) {
            this.ˎ.notify();
        }
    }

    private void ͺ() {
        do {
            try {
            } catch (Throwable e) {
                throw new IllegalStateException(e);
            }
        } while (ˊॱ());
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private boolean ˊॱ() throws java.lang.InterruptedException {
        /*
        r6 = this;
        r1 = 0;
        r2 = r6.ˎ;
        monitor-enter(r2);
    L_0x0004:
        r0 = r6.ͺ;	 Catch:{ all -> 0x0014 }
        if (r0 != 0) goto L_0x0017;
    L_0x0008:
        r0 = r6.ˏॱ();	 Catch:{ all -> 0x0014 }
        if (r0 != 0) goto L_0x0017;
    L_0x000e:
        r0 = r6.ˎ;	 Catch:{ all -> 0x0014 }
        r0.wait();	 Catch:{ all -> 0x0014 }
        goto L_0x0004;
    L_0x0014:
        r0 = move-exception;
        monitor-exit(r2);	 Catch:{ all -> 0x0014 }
        throw r0;
    L_0x0017:
        r0 = r6.ͺ;	 Catch:{ all -> 0x0014 }
        if (r0 == 0) goto L_0x001e;
    L_0x001b:
        monitor-exit(r2);	 Catch:{ all -> 0x0014 }
        r0 = r1;
    L_0x001d:
        return r0;
    L_0x001e:
        r0 = r6.ˊ;	 Catch:{ all -> 0x0014 }
        r0 = r0.removeFirst();	 Catch:{ all -> 0x0014 }
        r0 = (com.google.android.exoplayer2.decoder.DecoderInputBuffer) r0;	 Catch:{ all -> 0x0014 }
        r3 = r6.ʻ;	 Catch:{ all -> 0x0014 }
        r4 = r6.ʽ;	 Catch:{ all -> 0x0014 }
        r4 = r4 + -1;
        r6.ʽ = r4;	 Catch:{ all -> 0x0014 }
        r3 = r3[r4];	 Catch:{ all -> 0x0014 }
        r4 = r6.ॱˊ;	 Catch:{ all -> 0x0014 }
        r5 = 0;
        r6.ॱˊ = r5;	 Catch:{ all -> 0x0014 }
        monitor-exit(r2);	 Catch:{ all -> 0x0014 }
        r2 = r0.ˏ();
        if (r2 == 0) goto L_0x0050;
    L_0x003c:
        r1 = 4;
        r3.ॱ(r1);
    L_0x0040:
        r1 = r6.ˎ;
        monitor-enter(r1);
        r2 = r6.ॱˊ;	 Catch:{ all -> 0x008e }
        if (r2 == 0) goto L_0x007e;
    L_0x0047:
        r3.ˋ();	 Catch:{ all -> 0x008e }
    L_0x004a:
        r6.ˋ(r0);	 Catch:{ all -> 0x008e }
        monitor-exit(r1);	 Catch:{ all -> 0x008e }
        r0 = 1;
        goto L_0x001d;
    L_0x0050:
        r2 = r0.i_();
        if (r2 == 0) goto L_0x005b;
    L_0x0056:
        r2 = -2147483648; // 0xffffffff80000000 float:-0.0 double:NaN;
        r3.ॱ(r2);
    L_0x005b:
        r2 = r6.ˋ(r0, r3, r4);	 Catch:{ RuntimeException -> 0x006b, OutOfMemoryError -> 0x0073 }
        r6.ʼ = r2;	 Catch:{ RuntimeException -> 0x006b, OutOfMemoryError -> 0x0073 }
    L_0x0061:
        r2 = r6.ʼ;
        if (r2 == 0) goto L_0x0040;
    L_0x0065:
        r2 = r6.ˎ;
        monitor-enter(r2);
        monitor-exit(r2);	 Catch:{ all -> 0x007b }
        r0 = r1;
        goto L_0x001d;
    L_0x006b:
        r2 = move-exception;
        r2 = r6.ॱ(r2);
        r6.ʼ = r2;
        goto L_0x0061;
    L_0x0073:
        r2 = move-exception;
        r2 = r6.ॱ(r2);
        r6.ʼ = r2;
        goto L_0x0061;
    L_0x007b:
        r0 = move-exception;
        monitor-exit(r2);	 Catch:{ all -> 0x007b }
        throw r0;
    L_0x007e:
        r2 = r3.i_();	 Catch:{ all -> 0x008e }
        if (r2 == 0) goto L_0x0091;
    L_0x0084:
        r2 = r6.ˊॱ;	 Catch:{ all -> 0x008e }
        r2 = r2 + 1;
        r6.ˊॱ = r2;	 Catch:{ all -> 0x008e }
        r3.ˋ();	 Catch:{ all -> 0x008e }
        goto L_0x004a;
    L_0x008e:
        r0 = move-exception;
        monitor-exit(r1);	 Catch:{ all -> 0x008e }
        throw r0;
    L_0x0091:
        r2 = r6.ˊॱ;	 Catch:{ all -> 0x008e }
        r3.ॱ = r2;	 Catch:{ all -> 0x008e }
        r2 = 0;
        r6.ˊॱ = r2;	 Catch:{ all -> 0x008e }
        r2 = r6.ˏ;	 Catch:{ all -> 0x008e }
        r2.addLast(r3);	 Catch:{ all -> 0x008e }
        goto L_0x004a;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.add.ˊॱ():boolean");
    }

    private boolean ˏॱ() {
        return !this.ˊ.isEmpty() && this.ʽ > 0;
    }

    private void ˋ(I i) {
        i.ˊ();
        DecoderInputBuffer[] decoderInputBufferArr = this.ˋ;
        int i2 = this.ᐝ;
        this.ᐝ = i2 + 1;
        decoderInputBufferArr[i2] = i;
    }

    private void ˎ(O o) {
        o.ˊ();
        acx[] o_acxArr = this.ʻ;
        int i = this.ʽ;
        this.ʽ = i + 1;
        o_acxArr[i] = o;
    }
}
